<template>
  <div>
    <SideMenu></SideMenu>
      <el-card style="width: 50%;height:500px;margin: 50px auto">
        <h2> 创建课程 </h2>
      <el-form v-model="form" style="text-align: left" ref="formRef" :model="form">
        <el-form-item label="课程分类" :label-width="formLabelWidth" prop="type">
          <el-input v-model="form.type" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="课程名称" :label-width="formLabelWidth" prop="lessonname">
          <el-input v-model="form.lessonname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="教师名称" :label-width="formLabelWidth" prop="teachername">
          <el-input v-model="form.teachername" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="课程信息" :label-width="formLabelWidth" prop="info">
          <el-input v-model="form.info" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="图片（暂未）" :label-width="formLabelWidth" prop="photo">
          <el-input  v-model="form.photo" autocomplete="off"></el-input>
        </el-form-item>
        <el-button style="margin-left: 220px"  @click="resetForm">重 置</el-button>
        <el-button style="margin-left: 50px" type="primary" @click="onSubmit">确 定</el-button>
      </el-form>
      </el-card>
  </div>
</template>

<script>
    import SideMenu from "./SideMenu";
  export default {
      components: {SideMenu},
    name: 'addLesson',
    data () {
      return {
        dialogFormVisible: false,
        form: {
            type: '',
            lessonname: '',
            teachername: '',
            info: '',
            uesrname: '',
          // abs: '',
        },
          responseResult: [],
        formLabelWidth: '120px'
      }
    },
    methods: {
        resetForm () {
            console.log(this)
            this.$refs.formRef.resetFields()
        },
      clear () {
        this.form = {
          id: '',
          title: '',
          author: '',
          date: '',
          cover: '',
          abs: '',
        }
      },
      onSubmit () {
        this.$axios
          .post('/addlesson', {
            type: this.form.type,
            lessonname: this.form.lessonname,
            teachername: this.form.teachername,
            uesrname: this.form.uesrname,
            info: this.form.info,
            photo: this.form.photo,
            username:window.sessionStorage.getItem('username')
            
          }).then(resp => {
          if (resp && resp.status === 200) {
            this.dialogFormVisible = false
              this.$message.success('添加成功');
            this.resetForm()
          }
            else if (successResponse.data.code === 400){
                this.$message.error('添加失败');
            }
            else{
                this.$message.error('存在相同名字的课程');
            }
        })
      }
    }
  }
</script>

<style scoped>
  .el-icon-circle-plus-outline {
    margin: 50px 0 0 20px;
    font-size: 100px;
    float: left;
    cursor: pointer;
  }
</style>
